package com.lifeonwalden.fincalc.finance.service;

import java.math.BigDecimal;
import java.math.RoundingMode;

public interface RiskReturnCalculator {
    /**
     * 计算sharpe比率
     *
     * @param returnRate         收益率
     * @param riskFreeReturnRate 无风险收益率
     * @param volatility         波动率
     * @return
     */
    static BigDecimal calcSharpeRatio(BigDecimal returnRate, BigDecimal riskFreeReturnRate, BigDecimal volatility) {
        return returnRate.subtract(riskFreeReturnRate).divide(volatility, 4, RoundingMode.HALF_UP);
    }

    /**
     * 计算calmar比率
     *
     * @param returnRate         收益率
     * @param riskFreeReturnRate 无风险收益率
     * @param mdd                最大回撤
     * @return
     */
    static BigDecimal calcCalmarRatio(BigDecimal returnRate, BigDecimal riskFreeReturnRate, BigDecimal mdd) {
        return returnRate.subtract(riskFreeReturnRate).divide(mdd.abs(), 4, RoundingMode.HALF_UP);
    }
}